import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { optionsListApi } from '/@/api/demo/select';
import { treeOptionsListApi } from '/@/api/demo/tree';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '渠道',
    align: 'center',
    dataIndex: 'channel',
  },
  {
    title: '结算区域',
    align: 'center',
    dataIndex: 'areas',
    customRender: ({ value }) => {
      // js数组转字符串
      if (!value) {
        return '';
      }
      const areas = value.join(',');
      return areas;
    },
  },
];

//查询数据
export const searchFormSchema: FormSchema[] = [];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '渠道',
    field: 'channel',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入渠道!' }];
    },
  },
  {
    label: '结算平台',
    field: 'platform',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入结算平台!' }];
    },
  },
  {
    label: '结算类型',
    field: 'type',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入结算类型!' }];
    },
  },
  {
    label: '结算区域',
    field: 'area',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入结算区域!' }];
    },
  },
  {
    label: '结算比例',
    field: 'fixRate',
    component: 'InputNumber',
  },
  {
    label: '结算其他保单比例',
    field: 'otherPolicyRate',
    component: 'InputNumber',
  },
  {
    label: '结算规则',
    field: 'rule',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入结算规则!' }];
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

export const formTableColumns: BasicColumn[] = [
  {
    title: '结算区域',
    align: 'center',
    dataIndex: 'area',

    editRow: true,
    editComponent: 'ApiTreeSelect',
    editRule: false,
    editComponentProps: {
      api: treeOptionsListApi,
      resultField: 'list',
    },
    width: 200,
  },
  {
    title: '结算平台',
    align: 'center',
    dataIndex: 'platform',
    editRow: true,
    editComponent: 'Select',
    editComponentProps: {
      options: [
        {
          label: 'Option1',
          value: '1',
        },
        {
          label: 'Option2',
          value: '2',
        },
        {
          label: 'Option3',
          value: '3',
        },
      ],
    },
    width: 200,
  },
  {
    title: '结算比例',
    dataIndex: 'fixRate',
    editRow: true,
    align: 'left',
    // 默认必填校验
    editRule: true,
    width: 150,
  },
  {
    title: '结算其他保单',
    dataIndex: 'otherPolicyRate',
    editRow: true,
    align: 'right',
    editRule: async (text) => {
      if (text === '2') {
        return '不能输入该值';
      }
      return '';
    },
  },
];
